package bio.file.transferStream;

import org.junit.Test;

import java.io.*;

/**
 * Instruction：测试转换流 - 转换文件的字符
 * 字节流 <--> 字符流
 * Author：@author MaLi
 */
public class TransferStream {
    @Test
    public void copy() {
        try(InputStreamReader reader = new InputStreamReader(new FileInputStream("utf8.txt"));
            OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("gbc.txt"), "gbk");) {
            System.out.println(reader.getEncoding());
            int x;
            while ((x = reader.read()) != -1) {
                writer.write(x);
            }
            writer.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
